package com.woniuxueyuan.config;

import com.woniuxueyuan.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * springmvc配置类
 * 配置类代替spring配置文件，项目启动会自动加载
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Resource
    private LoginInterceptor loginInterceptor;
    /**
     * 注册自定义拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)//添加自己拦截器,只能从容器中获取
                .addPathPatterns("/**")//配置拦截规则,拦截所有
                .excludePathPatterns("/user/login","/book/queryAll")//配置免拦截规则
                .order(1);//配置拦截器执行循序,数值越小越先执行
    }
}
